import sys
import time
import os
import re
import subprocess as sp
import pyperclip as pc


def func(isHelp=False):
    if(isHelp):
        return ["showip", "~ showip", "=ipList"]
    output = sp.check_output("ipconfig")  # a=os.popen("x") a.readline()
    outstr = output.decode("GBK")
    ipPattern = '[12]\\d+.\\d+.\\d+.\\d+'
    findstr = "IPv4.+" + ipPattern
    ipListRaw = sorted(re.findall(findstr, outstr))
    for i in ipListRaw:
        ip = re.findall(ipPattern, i)[0].split(".")
        print("\t" + (("{:>4}." * 4)[:-1]).format(ip[0], ip[1], ip[2], ip[3]))
    for i in range(len(ipListRaw)):
        print("{:>3}-".format(i), re.findall(ipPattern, ipListRaw[i])[0])
    copyInd = int(input('---'))
    pc.copy(re.findall(ipPattern, ipListRaw[copyInd])[0])
